@import './theme/default';
@import './theme/font';
@import './theme/timing-functions';
@import './mixins/pointer-events';

$outer-circle-size: 16px;
$inner-circle-size: 8px;
$inner-circle-offset: ($outer-circle-size - $inner-circle-size - 2px) * 0.5;

.zent-radio-group {
  display: inline-block;
  font-size: 0;

  > :not(.zent-radio-wrap) {
    @include font-normal;
  }
}

.zent-radio-wrap {
  display: inline-block;
  cursor: pointer;
  font-size: 0;
  margin: 0;
  padding: 0;
  margin-right: 24px;
  vertical-align: middle;

  &:last-child {
    margin-right: 0;
  }

  .zent-radio {
    position: relative;
    display: inline-block;
    white-space: nowrap;
    outline: none;
    vertical-align: middle;
    margin: 0;
    padding: 0;
    line-height: 1;

    & > input {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      top: 0;
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
      z-index: 1;
      opacity: 0;
      cursor: pointer;
    }

    &-label {
      @include font-normal;
      display: inline;
      margin-left: 8px;
      vertical-align: middle;
    }
  }

  .zent-radio-inner {
    @include theme-color(border-color, stroke, 5);
    @include theme-color(background-color, stroke, 9);
    position: relative;
    top: 0;
    left: 0;
    display: inline-block;
    width: $outer-circle-size;
    height: $outer-circle-size;
    border-radius: 50%;
    border-width: 1px;
    border-style: solid;
    box-sizing: border-box;
    vertical-align: middle;
    transition: all 0.1s;

    &::after {
      @include theme-color(background-color, stroke, 9);
      position: absolute;
      display: block;
      content: ' ';
      top: $inner-circle-offset;
      left: $inner-circle-offset;
      width: $inner-circle-size;
      height: $inner-circle-size;
      border-radius: 50%;
      transform: scale(0);
      transition: all 0.1s ease-in-out;
    }
  }

  &.zent-radio-checked {
    & > .zent-radio {
      & > .zent-radio-inner {
        @include theme-color(border-color, primary, 4);

        &::after {
          @include theme-color(background-color, primary, 4);
          transform: scale(1);
        }
      }
    }
  }

  &.zent-radio-disabled {
    cursor: not-allowed;

    & > .zent-radio {
      & > .zent-radio-inner {
        @include theme-color(background-color, stroke, 8);

        &::after {
          @include theme-color(background-color, stroke, 8);
        }
      }

      & > input[type='radio'] {
        @include prevent-pointer-events;
      }
    }

    &.zent-radio-checked > .zent-radio {
      & > .zent-radio-inner {
        @include theme-color(border-color, stroke, 5);

        &::after {
          @include theme-color(background-color, stroke, 5);
        }
      }
    }

    & .zent-radio-label {
      @include theme-color(color, stroke, 4);
    }
  }

  &:not(.zent-radio-disabled):hover {
    .zent-radio-inner {
      @include theme-color(border-color, primary, 4);
    }
  }
}

.zent-radio-button {
  @include font-normal;
  @include theme-color(color, stroke, 3);
  @include theme-color(border-color, stroke, 5);

  border-width: 1px;
  border-style: solid;
  position: relative;
  box-sizing: border-box;
  display: inline-block;
  padding: 5px 10px;
  text-align: center;
  transition: all 100ms $timing-fn-ease-in;

  > input[type='radio'] {
    appearance: none;
    outline: none;
    border: 0;
    padding: 0;
    margin: 0;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: block;
    cursor: pointer;
  }

  &:not(:first-child) {
    margin-left: -1px;
  }

  &:first-child {
    border-radius: 2px 0 0 2px;
  }

  &:last-child {
    border-radius: 0 2px 2px 0;
  }

  &:hover:not(&--disabled) {
    @include theme-color(color, primary, 4);
  }

  &--checked {
    @include theme-color(color, primary, 4);
    @include theme-color(border-color, primary, 4);
    @include theme-color(background-color, primary, 8);
    z-index: 1;
  }

  &--disabled {
    @include theme-color(color, stroke, 4);
    @include theme-color(background-color, stroke, 8);
    cursor: not-allowed;

    > input[type='radio'] {
      @include prevent-pointer-events;
    }

    &.zent-radio-button--checked {
      @include theme-color(background-color, stroke, 10);
      @include theme-color(border-color, stroke, 5);
      @include theme-color(color, stroke, 4);
    }
  }
}
